package com.pain.scaffold.admin.config;

import cn.hutool.extra.qrcode.QrConfig;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import lombok.Data;
import lombok.ToString;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.awt.*;

@Component
@ConfigurationProperties(prefix = "qrcode")
@Data
@ToString
public class QrCodeConfig {

    /**
     * 二维码宽度
     */
    private Integer width = 300;

    /**
     * 二维码高度
     */
    private Integer height = 300;

    /**
     * 边距：二维码和背景之间的边距
     */
    private  Integer margin = 3;

    /**
     * 前景色：二维码颜色,默认青色
     */
    private String foreColor = "cyan";

    /**
     * 背景色: 默认灰色
     */
    private String backColor = "gray";


    public QrConfig transform(){
       QrConfig config = new QrConfig();
       config.setMargin(this.margin);
       config.setForeColor(Color.CYAN);
       config.setBackColor(Color.GRAY);
       config.setWidth(this.width);
       config.setHeight(this.height);
       config.setErrorCorrection(ErrorCorrectionLevel.H);
       return config;
    }
}
